﻿@using SH = EMoney.IStock.Client.Framework.StringHelper;

@{
    Layout = null;
}

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta name="viewport" content="width=device-width" />
    <title>互动 问股</title>
    <link href="@ViewBag.PageCss" rel="stylesheet" type="text/css" id="linkcss"/>
    <script src="http://static.emoney.cn/js/libs/jquery.min.1.8.3.js" type="text/javascript"></script>
</head>
<body>
    <div class="main">
        <div class="top_bar">
            <div class="fl"><a href="javascript:;" class="menu_a on" flag="recent" hidefocus="true">最近问答</a><a href="javascript:;" class="menu_a" flag="my" hidefocus="true">我的问答</a></div>
            <div class="fr"><a href="javascript:;" class="edit" hidefocus="true">我要提问</a></div>
            <div class="clear"></div>
        </div>
        <div class="tc_loading" id="tc_loading" style="display:none">数据加载中...</div>
        <div class="mask" id="tc_mask" style="display:none"></div>
        <div id="scrollBox1" class="scrollBox" scrollflag style="margin-top:5px;">
            <div class="list" style="margin-right:15px;"></div>
        </div>
    </div>
    <div class="pop" style="display:none;z-index:99999;">
        <div class="close"><a href="javascript:;" hidefocus="true">
            <img src="@SH.GetStaticFile("IStockClientStatic/hd/images/blank.gif")" width="30" height="30" alt="" /></a></div>
        <div class="top">我要提问</div>
        <div class="ask">
            <textarea class="ipt">请输入您的问题</textarea>
        </div>
        <div class="btn_k">
            <div class="fl"><span style="color:#333333;">最多可输入100字符</span>&nbsp;&nbsp;&nbsp;&nbsp;<span id="spanMsg" style="color:red;"></span></div>
            <div class="fr"><a href="javascript:;" class="ask_btn" hidefocus="true">提问</a></div>
            <div class="clear"></div>
        </div>
    </div>
    <input type="hidden" id="hidCID" value="@ViewBag.CIU" />
    <input type="hidden" id="hidUID" value="@ViewBag.UserID" />
</body>
    <script src="@SH.GetStaticFile("IStockClientStatic/js/EMWEBUIscrollBar.js")" type="text/javascript"></script>
</html>
<script type="text/javascript">
    document.onselectstart = function () { return false; }
    document.onmousemove = function (e) { return false; }
    var www = "@Url.Content("~/")", delImg = "@SH.GetStaticFile("IStockClientStatic/hd/images/blank.gif")",
        userid = $("#hidUID").val(), cid = $("#hidCID").val(), curFlag = "recent";

    $(document).ready(function () {
        $(".scrollBox").jscroll({ W: "8px", IW: "8px", CurrT: 0, Bar: { Pos: "up" }, Btn: { btn: false }, Fn: function () { } }).hover(function (e) {
            var thisbx = $(this), scrlbr = $(this).find(".jscroll-e");
            if (!scrlbr.hasClass("non")) {
                scrlbr.addClass("mon").stop(true, true, false).show();
            }
        }, function (e) {
            var thisbx = $(this), scrlbr = $(this).find(".jscroll-e");
            if (!scrlbr.hasClass("non")) {
                scrlbr.removeClass("mon");
                if (scrlbr.hasClass("vxdrag")) { } else {
                    //scrlbr.fadeOut("slow");
                }
            }
        });

        $(window).bind('load resize', '', function () {
            $(document).queue(function () {
                $(document).dequeue();
                var winH = $(window).height();
                
                $("#scrollBox1").height(winH - $(".top_bar").height() - 30);

                ReSetScroll();
            });
        });

        $("#scrollBox1").height($(window).height() - $(".top_bar").height() - 30);
        
        $(".ask_btn").click(function () {
            var content = $(".ipt").val();

            if (content == "" || content == "请输入您的问题") {
                $("#spanMsg").html("请输入您的问题");
                $(".ipt").focus();
            }
            else if (content.length > 100)
            {
                $("#spanMsg").html("输入的问题超过最大长度");
            }
            else {
                $.ajax({
                    type: "post",
                    url: www + "hd/Ask",
                    data: { content: escape(content), cid: cid },
                    datatype: "text",
                    success: function (data) {
                        if (data == "1") {
                            $(".close").click();

                            if (curFlag == "my") {
                                $(".fl a")[1].click();
                            }
                        }
                        else {
                            alert(data);
                        }
                    },
                    beforeSend: function () {
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        //alert(XMLHttpRequest.status);
                    }
                });
            }
        });

        $(".fl a").click(function () {
            curFlag = $(this).attr("flag");
            $(this).addClass("on").siblings().removeClass("on");

            getlist(curFlag);
        });

        $(".edit").click(function () {
            $(".pop").show();
        });

        $(".close").click(function () {
            $(".ipt").val("请输入您的问题");
            $(".pop").hide();
        });

        $(".ipt").focus(function () {
            if ($(this).val() == "" || $(this).val() == "请输入您的问题") {
                $(this).val("");
            }
        });

        $(".ipt").blur(function () {
            if ($(this).val() == "") {
                $(this).val("请输入您的问题");
            }
        });

        $(".list").delegate(".auto_height", "mouseenter", function () {
            if ($(this).find(".del").size() > 0)
            {
                $(this).find(".del").show();
            }
        }).delegate(".auto_height", "mouseleave", function () {
            if ($(this).find(".del").size() > 0) {
                $(this).find(".del").hide();
                $(this).find(".xz_1").hide();
            }
        });

        $(".fl a")[0].click();
    });

    function getlist(flag) {
        var url = "";

        switch (flag) {
            case "recent":
                url = www + "hd/GetRecentReply";
                break;
            case "my":
                url = www + "hd/GetMyTopic";
                break;
            default:
                return;
                break;
        }

        $.ajax({
            type: "post",
            url: url,
            data: { cid: cid },
            datatype: "text",
            success: function (data) {
                if (data != "") {
                    var obj = eval('(' + data + ')');

                    if (obj != null && obj.length > 0) {
                        var html = "";

                        $.each(obj, function (i) {
                            if (obj[i] == null) {
                                return true;
                            }

                            html += "<div class=\"auto_height\">";

                            if (obj[i].authorid == userid) {
                                html += "<div class=\"del\" style='display:none;'><a hidefocus=\"true\" href=\"javascript:;\" onclick='del(this)'>";
                                html += "<img src=" + delImg + " width=\"56\" height=\"18\"  alt=\"\"/></a>";
                                html += "<div class=\"xz_1\" style='display:none;'><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
                                html += "<tr><td width=\"50%\" align=\"center\" style=\"border-right:1px solid #ccc;\"><a href=\"javascript:;\" hidefocus=\"true\" onclick='canceldel(this);'>取消</a></td>";
                                html += "<td width=\"50%\" align=\"center\"><a href=\"javascript:;\" hidefocus=\"true\" onclick=\"affirmdel(" + obj[i].topicid + ");\">确认</a></td></tr></table></div>";
                                html += "</div>";
                            }
                            html += "<div class=\"part1\">";
                            html += "<div class=\"tdk\">";
                            html += "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
                            html += "<tr>";
                            html += "<td width=\"100\" align=\"left\" valign=\"top\">";
                            html += "<div class=\"portrait\">";
                            html += "<img src=\"" + obj[i].userpicurl + "\" width=\"70\" height=\"70\" alt=\"\" /></div>";
                            html += "<div class=\"name\" title=\"" + obj[i].username + "\">" + obj[i].usernameshow + "</div>";
                            html += "</td>";
                            html += "<td align=\"left\" valign=\"top\">";
                            html += "<p class=\"tit1\">" + obj[i].topiccontent + "</p>";
                            html += "<div class=\"time1\"><span class=\"time_k\">" + obj[i].timeshow + "</span></div>";

                            if (obj[i].Reply != null && obj[i].Reply.topicid == obj[i].topicid) {
                                html += "<div class=\"reply\">";
                                html += "<div class=\"fl\">曾老师回复</div>";
                                html += "<div class=\"fr\"><span class=\"time_k\">" + obj[i].Reply.timeshow + "</span></div>";
                                html += "<div class=\"clear\"></div>";
                                html += "<div class=\"point\">";
                                html += "<div class=\"say\">";
                                html += "<p>" + obj[i].Reply.replycontent + "</p>";
                                html += "</div>";
                                html += "<div class=\"like\"><span></span>&nbsp;&nbsp;&nbsp;&nbsp;<a hidefocus=\"true\" href=\"javascript:;\" onclick='vote(" + obj[i].topicid + "," + obj[i].Reply.replyid + ",1,this," + obj[i].Reply.yes + ");' class=\"add\">（" + obj[i].Reply.yes + "）</a><a hidefocus=\"true\" href=\"javascript:;\" onclick='vote(" + obj[i].topicid + "," + obj[i].Reply.replyid + ",0,this," + obj[i].Reply.no + ");' class=\"minus\">（" + obj[i].Reply.no + "）</a></div>";
                                html += "</div>";
                                html += "</div>";
                            }

                            html += "</td>";
                            html += "</tr>";
                            html += "</table>";
                            html += "</div>";
                            html += "</div>";
                            html += "</div>";
                        });

                        $(".list").html(html);
                    }
                }
                else {
                    $(".list").html("<div style='text-align:center;font-size:12px;line-height:" + $("#scrollBox1").height() + "px;color:#828282;'>-- 暂无数据 --</div>");
                }

                ReSetScroll();

                $("#tc_loading").hide();
                $("#tc_mask").hide();
            },
            beforeSend: function () {
                $("#tc_loading").show();
                $("#tc_mask").show();
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                //alert(XMLHttpRequest.status);
            }
        });
    }

    function vote(tid, rid, flag, e, num) {        
        $.ajax({
            type: "post",
            url: www + "hd/Vote",
            data: { tid: tid, rid: rid, flag: flag },
            datatype: "text",
            success: function (data) {
                var tips = "";

                switch (data) {
                    case "1":
                        tips = "投票成功";
                        var votenum = parseInt(num) + 1;
                        $(e).html("（" + votenum + "）");
                        break;
                    case "-1":
                        tips = "已投票";
                        break;
                    default:
                        break;
                }
                
                $(e).parent().find("span").html(tips);

                setTimeout(function () { $(e).parent().find("span").html(""); }, 1000);
            },
            beforeSend: function () {
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                //alert(XMLHttpRequest.status);
            }
        });
    }

    function canceldel(e) {
        $(e).parent().parent().parent().parent().parent().hide();
    }

    function affirmdel(tid) {
        $.ajax({
            type: "post",
            url: www + "hd/del",
            data: { tid: tid, cid: cid },
            datatype: "text",
            success: function (data) {
                if (data == "1") {
                    getlist(curFlag);
                }
                else {
                }
            },
            beforeSend: function () {
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                //alert(XMLHttpRequest.status);
            }
        });
    }

    function del(e) {
        $(e).parent().find(".xz_1").show();
    }

    function OnSkinChanged(skinName) {
        var cssHref = "";

        switch (skinName) {
            case "default":
                cssHref = "@SH.GetStaticFile("IStockClientStatic/hd/css/main.css")";
                break;
            case "black":
                cssHref = "@SH.GetStaticFile("IStockClientStatic/hd/css/main1.css")";
                break;
            default:
                break;
        }

        if (cssHref != "") {
            $("#linkcss").attr("href", cssHref);
        }
    }
</script>
